package cn.com.nes.site.controller.contract;

import cn.com.nes.common.web.CommonResult;
import cn.com.nes.site.controller.contract.vo.ContractPageVO;
import cn.com.nes.site.controller.contract.vo.ContractSaveVO;
import cn.com.nes.site.service.contract.ContractBusinessService;
import cn.com.nes.site.service.contract.bo.ContractSaveBO;
import cn.com.nes.site.service.contract.dto.ContractDTO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Api(tags = {"合同管理-合同管理"})
@Controller
@RequestMapping("/v2/contract")
public class ContractController {

    @Resource
    private ContractBusinessService contractBusinessService;

    @ApiOperation(value = "查询合同列表-分页")
    @RequestMapping(value = "/getContractPage", method = RequestMethod.GET)
    public @ResponseBody CommonResult<ContractDTO> getContractPage(ContractPageVO contractPageVO) throws Exception {
        Page<ContractDTO> contractPage = contractBusinessService.getContractPage(contractPageVO.convertToBo());
        return CommonResult.page(contractPage);
    }

    @ApiOperation(value = "保存合同")
    @RequestMapping(value = "/saveContract", method = RequestMethod.POST)
    public @ResponseBody CommonResult<ContractDTO> saveContract(
            @RequestBody @Validated ContractSaveVO contractSaveVO) throws Exception {
        ContractDTO contractDTO = contractBusinessService.saveContract(contractSaveVO.convertToBo(ContractSaveBO.class));
        return CommonResult.data(contractDTO);
    }

}
